<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <style>
        img{
            width: 40px;
            height: 40px;
        }
    </style>
</head>
<body>
    <div id="app">
        
        <table class="table table-hover">
            <thead>
                <tr>
                    <th>编号</th>
                    <th>姓名</th>
                    <th>年龄</th>
                    <th style="width: 100px;">图片</th>
                    <th>爱好</th>
                    <th>状态</th>
                    <th>点赞</th>
                </tr>
            </thead>
            <tbody>
                <tr v-for="item of members" :key="item._id">
                    <!-- <td v-for="i of item">{{i}}</td> -->
                    <td>{{item._id}}</td>
                    <td>{{item.name}}</td>
                    <td>{{item.age}}</td>
                    <td>{{item.imageUrl}}</td>
                    <td>{{item.like}}</td>
                    <td>{{item.playStates}}</td>
                    <td>
                        <img :src="item.playStates?'../images/pause.png':'../images/play.png'" alt="" 
                        @click="handle(item._id)">
                    </td>
                    <td>
                    <button type="button" class="btn btn-default" @click="doDelete(item._id)">删除</button>
                    <button type="button" class="btn btn-default">修改</button>
                    </td>
                    <!-- <td>
                        <img   @click="handle(item._id)" 
                        :src="playStates==item._id?'@/../../images/play.png':'@/../../images/pause.png'">
                    </td> -->
                </tr>
            </tbody>
        </table>
        
    </div>
    <script>
        new Vue({
            el:"#app",
            data:{
                members:[],
                mark:-1,
                playStates:0
            },
            /* 
            data(){
                    return {
                        playpng:require("../images/play.png")
                    }
                }
            */
            mounted(){
                $.ajax({
                    url:"http://localhost:8081/members"
                }).then(res=>{
                    this.members = res.data
                })
            },
            methods:{
                doDelete(id){
                    this.members = this.members.filter(item=>item._id !=id);
                    $.ajax({
                        url:"http://localhost:8081/doDelete",
                        type:"post",
                        data:{
                            id
                        }
                    }).then(res=>{
                        console.log(res)
                    })
                    
                },
                // handle(playStates){
                //     // this.playStates=id;
                //     // console.log(id)
                //     if(playStates == this.mark){
                //         this.mark = -1 
                //     }else{
                //     this.mark = playStates
                //     }
                //     console.log(playStates)
                // },
                handle(id){
                    var members = this.members;
                    var item = members.find(item=>item._id == id)
                    // console.log(item)
                    
                    // item.playStates = !item.playStates
                    if(item.playStates){
                        item.playStates = false
                    }else{
                        item.playStates = true
                    }
                    // this.members = members//若没有下面http请求内容，这一行要加上
                    console.log(item.playStates)
                    $.ajax({
                        url:"http://localhost:8081/doLike",
                        method:"post",
                        data:{
                            id,
                            playStates:item.playStates
                        }
                    }).then(res=>{
                        console.log(res)//404
                        
                    })
                }
                
                
            }
        })
    </script>
</body>
</html>